package com.sc.HadoopWC;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import com.sc.bean.WordInfo;
import com.sc.mapper.WordCountMapper;
import com.sc.mapper.ZHWCSsortMapper;
import com.sc.mapper.ZHWordCountMapper;
import com.sc.reducer.SortCombiner;
import com.sc.reducer.WordCountReducer;
import com.sc.reducer.ZHWCSortReducer;

/**
 * Hello world!
 *
 */
public class App 
{
    @SuppressWarnings("deprecation")
	public static void main( String[] args ) throws IOException, ClassNotFoundException, InterruptedException
    {
    	//程序启动
        Configuration configuration = new Configuration();
        Job job = new Job(configuration);
        
        //设置包含main的类
        job.setJarByClass(App.class);
        
        //设置mapper类
//        job.setMapperClass(WordCountMapper.class);
//        job.setMapperClass(ZHWordCountMapper.class);
        job.setMapperClass(ZHWCSsortMapper.class);
        
        //设置reducer类
//        job.setReducerClass(WordCountReducer.class);
        job.setReducerClass(ZHWCSortReducer.class);
        
        //设置Combiner
//        job.setCombinerClass(SortCombiner.class);
        
        
        //设置输出键和值类型
        job.setMapOutputKeyClass(WordInfo.class);
        job.setMapOutputValueClass(NullWritable.class);
        
        job.setOutputKeyClass(WordInfo.class);
        job.setOutputValueClass(NullWritable.class);
        
        //设置hadoop的文件路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        //结果输出路径
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        
        //等待打印日志
        job.waitForCompletion(true);
        
    }
}
